import React, { useState, useEffect } from 'react'
import { View ,Image } from '@tarojs/components'
import Taro,{useDidShow} from '@tarojs/taro'
import api from '../../../http/api'
// import nav1 from '../img/nav1.png'
// import nav2 from '../img/nav2.png'
// import nav3 from '../img/nav3.png'
// import nav4 from '../img/nav4.png'
// import nav5 from '../img/nav5.png'
// import nav6 from '../img/nav6.png'

import './index.less'

export default (props: any) => {
  const [navList,setNavList] = useState([
    {
      ico: IMGSRC+'nav1.png',
      txt: 'U选商家'
    },
    {
      ico: IMGSRC+'nav2.png',
      txt: '校园活动'
    },
    {
      ico: IMGSRC+'nav3.png',
      txt: '校园广场'
    },
    // {
    //   ico: nav4,
    //   txt: '打字复印'
    // },
    // {
    //   ico: IMGSRC+'nav5.png',
    //   txt: '商户入驻'
    // },
    // {
    //   ico: nav6,
    //   txt: '签到'
    // },
  ])
  const navClick=(item:any)=>{
    if(item.txt==='U选商家'){
      Taro.switchTab({
        url:'/pages/uBusiness/index'
      })
    }else if(item.txt==='校园活动'){
      Taro.switchTab({
        url:'/pages/active/index'
      })
    }else if(item.txt==='校园广场'){
      Taro.switchTab({
        url:'/pages/news/index'
      })
    }else if(item.txt==='商户入驻'){
      Taro.navigateTo({
        url:'/pages/businessEnter/index'
      })
    }else if(item.txt==='新生专区'){
      Taro.navigateTo({
        url:'/pages/nsBusiness/index'
      })
    }
  }
  useDidShow(()=>{
    api.version().then((res:any)=>{
      const version = res.data
      if(version ===1){
        setNavList([
          {
            ico: IMGSRC+'nav1.png',
            txt: 'U选商家'
          },
          {
            ico: IMGSRC+'nav2.png',
            txt: '校园活动'
          },
          {
            ico: IMGSRC+'nav3.png',
            txt: '校园广场'
          },
          {
            ico: IMGSRC+'nav7.png',
            txt: '新生专区'
          },
        ])
      }
    })
  })
  return (
    <View className='navUl'>
        {
          navList.map((item, i) => (
            <View className='navLi' onClick={()=>{navClick(item)}}>
              <Image className='ico' src={item.ico}></Image>
              <View  className='txt'>{item.txt}</View>
            </View>
          ))
        }
      </View>
  );
};
